<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>
	<button id="get">get获取</button>
	<input type="text" id="bookname_input">
	<input type="text" id="author_input">
	<input type="text" id="publisher_input">
	<button id="post">post提交</button>
	<script>
		get.onclick = function(){
			// 不带参数
			fetch('http://www.liulongbin.top:3006/api/getbooks',{
				method:'get'
			})
			// 带参数
			// fetch('http://www.liulongbin.top:3006/api/getbooks?id=1',{
			// 	method:'get'
			// })
			.then(function(res){
				return res.json()
			})
			.then(res=>{
				console.log(res)
			})
		}
		post.onclick = function(){
			var bookname = bookname_input.value;
			var author = author_input.value;
			var publisher = publisher_input.value;
			let obj = JSON.stringify({ bookname, author, publisher});
			fetch('http://www.liulongbin.top:3006/api/addbook',{
				method:'post',
				headers:{
					'Content-Type':'application/json'
				},
				body:obj
			}).then(res=> res.json()).then(res=>console.log(res))
		}
	</script>
</body>
</html>